CategoryView = {
	maxItem: 6,
	ctrl: CategoryController,

	createCategoriesNode : function(arrCategories,arrBooks) {
		// Declare Category
		var key = "books";
		addActive(key);
		var rootNodeCategory = $id("category-list");
		var category = null;
		var nodeUl=null;
		var nodeLi=null;
		var nodeCategory = null;
		var lengthCategory = arrCategories.length;

		// Declare ListBook
		var rootNodeListBook = $id("productItems");
		var book = null;
		var nodeItem = null;
		var nodeImg = null;
		var nodeItembot = null;
		var nodeName = null;
		var nodePrice = null;
		var lengthListBook = arrBooks.length;
		var pos = this.ctrl.pos * 12;

		// Delete child node
		rootNodeCategory.innerHTML = "";
		rootNodeListBook.innerHTML = "";

		// Set node Category
        var self = this;
		nodeUl = createNode("ul");
		for (var i = 0; i < lengthCategory; i++) {
			category = arrCategories[i];
			
			nodeLi = createNode("li");
			
			nodeCategory = createNode("a");
			nodeCategory.setText(category.CategoryName);
			nodeCategory.setAttribute("href","#");			
			nodeCategory.setAttribute("categoryId", category.CategoryId);
			nodeCategory.addEventListener("click", function(event) {	
				self.ctrl.page = 0;							
				self.ctrl.callServiceBooks(parseInt(event.currentTarget.attributes.categoryId.textContent),null);
			});

			nodeUl.appendChild(nodeLi);
			nodeLi.appendChild(nodeCategory);
		}
		rootNodeCategory.appendChild(nodeUl);
		
		lengthListBook = pos + 12 > lengthListBook ? lengthListBook : pos + 12;
		// Set node ListBook
		for (var i = pos; i < lengthListBook; i++) {
			book = arrBooks[i];

			nodeItem = createNode("a");
			nodeItem.addClass("item");
			nodeItem.setAttribute("href","#");
			nodeItem.setAttribute("id",book.BookId);
			nodeItem.addEventListener("click", getProductDetail,false); 

			nodeImg = createNode("img");
			nodeImg.addClass("item-img");
			nodeImg.src = book.Pic;
			
			nodeItembot = createDiv();
			nodeItembot.addClass("item-bot");

			nodeName = createDiv();
			nodeName.addClass("item-name");
			nodeName.setText(book.Name);

			nodePrice = createDiv();
			nodePrice.addClass("item-price");
			nodePrice.setText(book.Price);
			
			rootNodeListBook.appendChild(nodeItem);

			nodeItem.appendChild(nodeImg);
			nodeItem.appendChild(nodeItembot);

			nodeItembot.appendChild(nodeName);
			nodeItembot.appendChild(nodePrice);
		}
	},
	
	updateView: function() {
		this.createCategoriesNode(this.ctrl.model.Categories, this.ctrl.model.Books);
	}
};
